/**
 * Project Name:jbase
 * File Name:DB.java
 * Package Name:jbase.project.system.net.http.websearcher
 * Date:2017年4月30日下午10:01:43
 * Copyright (c) 2017, chenzhou1025@126.com All Rights Reserved.
 *
*/

package jbase.project.system.net.http.websearcher;

import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;

import jbase.project.system.core.InterfaceProxyFactory;
import jbase.project.system.core.common.EventHook;
import jbase.project.system.exception.SysException;

/**
 * ClassName:DB <br/>
 * Function: TODO ADD FUNCTION. <br/>
 * Reason: TODO ADD REASON. <br/>
 * Date: 2017年4月30日 下午10:01:43 <br/>
 * 
 * @author Licheng
 * @version
 * @since JDK 1.8
 * @see
 */
public class DerbyDBWebSearcherLauncher {

	public static void main(String[] args) throws ClassNotFoundException, SQLException, SysException {

		EventHook hook = InterfaceProxyFactory.newInstance().makeProxy((proxy, method, arguments) -> {
			System.out.printf("method %s invoked, parameters:\n", method.getName());
			String event = (String) arguments[0];
			if (event.equals("DownloadSourceFound")) {
				System.out.println("download:" + (String) ((Object[]) arguments[1])[0]);
			} else if (event.equals("with")) {
				System.out.println("with:" + (String) ((Object[]) arguments[1])[0]);
			}
			return null;
		}, EventHook.class);

		DerbyDBServiceProvider dp = new DerbyDBServiceProvider("H:\\ivsky\\mdb", "H:\\ivsky\\imgs");

		List<String> include = Arrays.asList(".*[wW]{3}\\.[iI][vV][sS][kK][yY]\\.[cC][oO][mM]/.*");
		List<String> exclude = Arrays.asList();
		List<String> downRegex = Arrays.asList(".*\\.([Jj][Pp][Ee]?[Gg]|[Pp][Nn][Gg]|[Gg][Ii][Ff]|[Bb][Mm][Pp])");
		List<String> starturl = Arrays.asList("http://www.ivsky.com/");
		dp.addConfig("allow", include.get(0));
		dp.addConfig("down", downRegex.get(0));
		dp.addURLToTasks(starturl.get(0));

		WebSearcher finder = new WebSearcher(hook, dp);
		finder.start();

	}

}
